WEBVTT

00:00.090 --> 00:03.180
Hello and welcome back to this session about random numbers.

00:03.180 --> 00:08.750
So creating random numbers is a very helpful to you to assimilate and analyze the real world processes

00:08.790 --> 00:10.460
like playing the lottery.

00:10.500 --> 00:16.020
So if you are good and Massa so has six you can simply calculate the likelihood of winning a lottery.

00:16.020 --> 00:22.140
But if you don't have any clue about math and still has six yeah you can also assimilate this process

00:22.140 --> 00:29.760
by generating random numbers and analyze and the results of your simulation so first of all let's impart

00:29.760 --> 00:32.880
them the random module so it's not imparted by default.

00:33.450 --> 00:40.350
So we need to impart it with them the keyboard impart and then with the function random that random

00:40.800 --> 00:44.880
we can generate random floats in the interval 0 2 1.

00:44.880 --> 00:48.840
So if you press surf tab we can never look here.

00:48.990 --> 00:58.480
So it's in the interval a 0 2 1 until we get 0 point 5 to 3 something and the fear read around the cell

01:00.530 --> 01:02.460
we get another random float.

01:02.630 --> 01:04.730
Also on the Internet a 0 to 1.

01:04.730 --> 01:07.300
So it's 0 point 8 9.

01:07.640 --> 01:14.750
And every time we repeat this process we get another random float in the interval 0 to 1 and that's

01:14.810 --> 01:21.390
a very helpful tool called the random seed where you can pass within the brackets a number here it's

01:21.400 --> 01:21.990
one two three.

01:22.010 --> 01:23.540
But it can be any number.

01:23.900 --> 01:28.270
And when we create random numbers like here we need to set up the random seed before.

01:29.000 --> 01:33.670
And as long as we have the same random seed we get the same random numbers.

01:33.800 --> 01:40.250
So the random numbers are still random but we are so-called pseudo random because then they depend on

01:40.250 --> 01:41.360
the random seed.

01:41.540 --> 01:47.300
And this enables reproducibility so as long as you have the same seed as I have.

01:47.300 --> 01:54.540
So here in this case one two three we should get them the same random numbers so let's run here.

01:54.570 --> 01:56.790
The salad with the random seed one two three.

01:56.790 --> 02:04.590
So we still use the random generator random at random so we would expect a random float between 0 and

02:04.590 --> 02:06.580
1.

02:06.630 --> 02:09.080
So here we have 0 point 0 5 2.

02:09.510 --> 02:14.190
And uh if we repeat this process we should actually get the same random float

02:17.020 --> 02:22.800
and this is the case so when the feed change here the random seed to say let's take 10.

02:22.960 --> 02:29.770
So it can be any number here then we get a different random number hits or point five seven.

02:29.990 --> 02:34.760
And if we repeat this process we get the same number because we have the same seed as before

02:37.550 --> 02:43.940
and depending on the characteristics of our real world problem the different the random generating functions.

02:43.940 --> 02:51.190
So here we learn about the random that random function that creates floats in the interval 0 2 1.

02:51.330 --> 02:57.500
And that's also the function random dot rent in which creates random integers in an interview which

02:57.500 --> 02:58.880
we can determine actually.

02:58.880 --> 03:02.040
So let's press shift tap and have a look.

03:02.120 --> 03:07.380
So here return random integer and range a to b including both and points.

03:07.430 --> 03:14.540
So if you want to generate a random integer and Range 1 to 100 both ends including then our function

03:14.540 --> 03:18.680
here is random dot rent and from 1 to 100.

03:18.680 --> 03:21.200
So let's run the cell here.

03:21.400 --> 03:31.160
Here we get 55 and you can also repeated so without random CTF we get different integers and let's assume

03:31.160 --> 03:33.820
we have the problem of rolling the dice.

03:33.830 --> 03:43.210
Yeah we can simulate rolling the dice by creating random integers and the Range 1 2 6 so now first throw

03:43.300 --> 03:54.670
we get five and now a second throw one in our third throw two and so on and we can also create many

03:54.670 --> 03:58.060
random numbers with a for loop.

03:58.510 --> 04:05.620
So first of all we create an empty list and we set up the random C to 1 2 3 so we want to have the same

04:05.620 --> 04:06.330
random numbers.

04:06.340 --> 04:13.420
If we repeat the process here and then we say we want to have 10 random integers and Range 1 to 100.

04:13.420 --> 04:21.520
So we have a for loop with are 10 iterations so ten times we create a random in the 10 range.

04:21.510 --> 04:27.630
1 2 100 and each random integer We append to our list.

04:28.690 --> 04:31.980
So let's see what we get.

04:32.420 --> 04:35.830
And we can print out here.

04:35.940 --> 04:41.270
So here we have a list with 10 random integers and range one to one hundred and that.

04:41.280 --> 04:46.950
Also the length of added so of course we have 10 random integers and we can also simply change this.

04:46.980 --> 04:55.950
So let's assume that we want to simulate rolling the dice 10 times then we can say OK I want to create

04:55.950 --> 04:58.110
random in the just in range 1 to 6

05:01.600 --> 05:05.770
and here we have the result of simulating rolling the dice 10 times.

05:05.770 --> 05:10.510
So we have 1 3 1 4 3 1 1 4 5 5.

05:10.630 --> 05:15.640
And as I said depending on the characteristics of our real world problem there are many more random

05:15.940 --> 05:17.720
functions.

05:17.770 --> 05:22.090
So if you press your shift tap.

05:22.140 --> 05:27.380
So for example we can create like normal random numbers or normal random numbers.

05:27.390 --> 05:31.870
So there are a lot of options here.

05:31.990 --> 05:32.290
All right.

05:32.290 --> 05:35.410
So let's create some number distribute the numbers.

05:35.470 --> 05:42.470
Let's have a look at just tap so here we are creating normal distributed numbers.

05:42.530 --> 05:46.190
With the U.S. and the mean and seek mass the standard deviation.

05:46.190 --> 05:51.820
So let's assume we are we have a mean of 10 and a standard deviation of 5.

05:51.830 --> 05:58.280
Then we can create a random number from the normal distribution with the mean 10 and standard deviation

05:58.280 --> 05:59.210
5.

05:59.210 --> 06:02.120
So in this example 0 point to 6.

06:02.120 --> 06:02.480
All right.

06:02.480 --> 06:06.740
So we are finished now with the random module and later we can see that also name pi.

06:06.770 --> 06:12.720
There's a random module it's a uprights actually even more functionality and more options then than

06:12.740 --> 06:15.640
the adding module here in the past the standard library.

06:15.710 --> 06:18.660
So hope you enjoyed it and you we see us in the next lesson.

06:18.680 --> 06:18.890
But.
